package com.sirun.cn.fca.module.main.home.temp.repo;

import com.sirun.cn.fca.module.main.home.temp.VehicleRespons;
import com.tencent.cloud.iov.kernel.constant.ApiConst;
import com.tencent.cloud.iov.kernel.model.BaseResponse;
import com.tencent.cloud.iov.kernel.service.ServiceGenerator;
import com.tencent.cloud.iov.kernel.service.interceptor.ExceptionTransformer;

import io.reactivex.Observable;

public class ControlRepository {
    private static volatile ControlRepository sInstance;

    public static ControlRepository getInstance() {
        if (sInstance == null) {
            synchronized (ControlRepository.class) {
                if (sInstance == null) {
                    sInstance = new ControlRepository();
                }
            }
        }

        return sInstance;
    }

    private final ControlService mControlService;

    private ControlRepository() {
        mControlService = ServiceGenerator.createService(ControlService.class, ApiConst.getBaseUrl());
    }

    public Observable<BaseResponse<ControlResponse>> controlDoor(String din, ControlRequest request) {
        return mControlService.controlDoor(din, request)
                .compose(new ExceptionTransformer<ControlResponse>());
    }

    public Observable<BaseResponse<ControlResponse>> controlEngine(String din, ControlRequest request) {
        return mControlService.controlEngine(din, request)
                .compose(new ExceptionTransformer<ControlResponse>());
    }

    public Observable<BaseResponse<ControlResponse>> controlBeer(String din, ControlRequest request) {
        return mControlService.controlBeer(din, request)
                .compose(new ExceptionTransformer<ControlResponse>());
    }

    public Observable<BaseResponse<ControlPollingResponse>> controlPolling(String din, String platformResponseId) {
        return mControlService.controlPolling(din, platformResponseId)
                .compose(new ExceptionTransformer<ControlPollingResponse>());
    }

    public Observable<BaseResponse<ControlResponse>> controlCar(String type, String din, ControlRequest request) {
        return mControlService.controlCar(type, din, request)
                .compose(new ExceptionTransformer<ControlResponse>());
    }

    public Observable<BaseResponse<VehicleRespons>> getVehicele() {
        return mControlService.getVehicle()
                .compose(new ExceptionTransformer<VehicleRespons>());
    }
}
